package com.ai.filter;

import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.context.ApplicationListener;

import java.net.InetAddress;

/**
 * 通过监听器获取服务IP信息
 */
public class IpListener implements ApplicationListener<ApplicationStartingEvent> {
    @Override
    public void onApplicationEvent(ApplicationStartingEvent event) {
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            System.setProperty("server.ip", ip);
        } catch (Exception e) {
            System.setProperty("server.ip", "localhost");
        }
    }
}
